namespace SimpleWebServices.Web
{
    using System;
    using System.Web;
    using Moq;
    using SimpleWebServices.Configuration;
    using Xunit;

    public sealed class HttpRequestBaseTenantExtensionMethodsFacts
    {
        [Fact]
        public void typedef()
        {
            Assert.True(typeof(HttpRequestBaseTenantExtensionMethods).IsStatic());
        }

        [Fact]
        public void op_TenantContentPath_HttpRequestBase()
        {
            RelativeUri expected = "/test";

            var mock = new Mock<HttpRequestBase>();
            mock.SetupGet<string>(x => x.Path).Returns("/example/test").Verifiable();

            RelativeUri actual = mock.Object.TenantContentPath();

            Assert.Equal<RelativeUri>(expected, actual);

            mock.VerifyAll();
        }

        [Fact]
        public void op_TenantContentPath_HttpRequestBase_whenNested()
        {
            RelativeUri expected = "/test/form";

            var mock = new Mock<HttpRequestBase>();
            mock.SetupGet<string>(x => x.Path).Returns("/example/test/form").Verifiable();

            RelativeUri actual = mock.Object.TenantContentPath();

            Assert.Equal<RelativeUri>(expected, actual);

            mock.VerifyAll();
        }

        [Fact]
        public void op_TenantContentPath_HttpRequestBase_whenRootPath()
        {
            var mock = new Mock<HttpRequestBase>();
            mock.SetupGet<string>(x => x.Path).Returns("/").Verifiable();

            Assert.Null(mock.Object.TenantContentPath());

            mock.VerifyAll();
        }

        [Fact]
        public void op_TenantContentPath_HttpRequestBase_whenTenantRootPath()
        {
            var mock = new Mock<HttpRequestBase>();
            mock.SetupGet<string>(x => x.Path).Returns("/example/").Verifiable();

            Assert.Null(mock.Object.TenantContentPath());

            mock.VerifyAll();
        }

        [Fact]
        public void op_TenantContentPath_HttpRequestBaseNull()
        {
            Assert.Throws<ArgumentNullException>(() => (null as HttpRequestBase).TenantContentPath());
        }

        [Fact]
        public void op_TenantPath_HttpRequestBase()
        {
            RelativeUri expected = "/example";

            var mock = new Mock<HttpRequestBase>();
            mock.SetupGet<string>(x => x.Path).Returns("/example").Verifiable();

            RelativeUri actual = mock.Object.TenantPath();

            Assert.Equal<RelativeUri>(expected, actual);

            mock.VerifyAll();
        }

        [Fact]
        public void op_TenantPath_HttpRequestBase_whenNested()
        {
            RelativeUri expected = "/example";

            var mock = new Mock<HttpRequestBase>();
            mock.SetupGet<string>(x => x.Path).Returns("/example/test").Verifiable();

            RelativeUri actual = mock.Object.TenantPath();

            Assert.Equal<RelativeUri>(expected, actual);

            mock.VerifyAll();
        }

        [Fact]
        public void op_TenantPath_HttpRequestBase_whenRootPath()
        {
            var mock = new Mock<HttpRequestBase>();
            mock.SetupGet<string>(x => x.Path).Returns("/").Verifiable();

            Assert.Null(mock.Object.TenantPath());

            mock.VerifyAll();
        }

        [Fact]
        public void op_TenantPath_HttpRequestBaseNull()
        {
            Assert.Throws<ArgumentNullException>(() => (null as HttpRequestBase).TenantPath());
        }

        [Fact]
        public void op_TenantPath_HttpRequestBase_int()
        {
            RelativeUri expected = "/test";

            var mock = new Mock<HttpRequestBase>();
            mock.SetupGet<string>(x => x.Path).Returns("/example/test").Verifiable();

            RelativeUri actual = mock.Object.TenantPath(1);

            Assert.Equal<RelativeUri>(expected, actual);

            mock.VerifyAll();
        }

        [Fact]
        public void op_TenantPath_HttpRequestBase_int_whenNested()
        {
            RelativeUri expected = "/test";

            var mock = new Mock<HttpRequestBase>();
            mock.SetupGet<string>(x => x.Path).Returns("/example/test/form").Verifiable();

            RelativeUri actual = mock.Object.TenantPath(1);

            Assert.Equal<RelativeUri>(expected, actual);

            mock.VerifyAll();
        }

        [Fact]
        public void op_TenantPath_HttpRequestBase_int_whenRootPath()
        {
            var mock = new Mock<HttpRequestBase>();
            mock.SetupGet<string>(x => x.Path).Returns("/").Verifiable();

            Assert.Null(mock.Object.TenantPath(1));

            mock.VerifyAll();
        }

        [Fact]
        public void op_TenantPath_HttpRequestBase_int_whenTenantRootPath()
        {
            var mock = new Mock<HttpRequestBase>();
            mock.SetupGet<string>(x => x.Path).Returns("/example/").Verifiable();

            Assert.Null(mock.Object.TenantPath(1));

            mock.VerifyAll();
        }

        [Fact]
        public void op_TenantPath_HttpRequestBaseNull_int()
        {
            Assert.Throws<ArgumentNullException>(() => (null as HttpRequestBase).TenantPath(0));
        }

        [Fact]
        public void op_TenantPath_HttpRequestBase_intNegative()
        {
            Assert.Throws<ArgumentOutOfRangeException>(() => new Mock<HttpRequestBase>().Object.TenantPath(-1));
        }

        [Fact]
        public void op_TenantUrn_HttpRequestBase()
        {
            AbsoluteUri expected = "urn://example.com/tenant/sample";

            var mock = new Mock<HttpRequestBase>();
            mock.SetupGet<string>(x => x.Path).Returns("/sample").Verifiable();

            AbsoluteUri actual = mock.Object.TenantUrn();

            Assert.Equal<AbsoluteUri>(expected, actual);

            mock.VerifyAll();
        }

        [Fact]
        public void op_TenantUrn_HttpRequestBase_whenNested()
        {
            AbsoluteUri expected = "urn://example.com/tenant/sample";

            var mock = new Mock<HttpRequestBase>();
            mock.SetupGet<string>(x => x.Path).Returns("/sample/test").Verifiable();

            AbsoluteUri actual = mock.Object.TenantUrn();

            Assert.Equal<AbsoluteUri>(expected, actual);

            mock.VerifyAll();
        }

        [Fact]
        public void op_TenantUrn_HttpRequestBase_whenRootPath()
        {
            var mock = new Mock<HttpRequestBase>();
            mock.SetupGet<string>(x => x.Path).Returns("/").Verifiable();

            Assert.Null(mock.Object.TenantUrn());

            mock.VerifyAll();
        }

        [Fact]
        public void op_TenantUrn_HttpRequestBaseNull()
        {
            Assert.Throws<ArgumentNullException>(() => (null as HttpRequestBase).TenantUrn());
        }
    }
}